﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EvadeState : Istate
{
    enemy parent;
    public void enter(enemy parent)
    {
        this.parent = parent;
    }

    public void exit()
    {
        parent.Xdir = 0;
        parent.Ydir = 0;
    }

    public void update()
    {
        parent.Xdir = parent.MyStartPosition.x - parent.transform.position.x;
        parent.Ydir = parent.MyStartPosition.y - parent.transform.position.y;
        parent.transform.position = Vector2.MoveTowards(parent.transform.position, 
                                                        parent.MyStartPosition, 
                                                        parent.MySpd * Time.deltaTime);

        //vector2 distance<=0
        float distance = Vector2.Distance(parent.transform.position, parent.MyStartPosition);
        if (distance <= 0)
        {
            parent.changeState(new IdleState());
        }
    }
}
